CFLAGS ?= -O2
PICFLAG = -fPIC
C99FLAG = -std=c99
-WCFLAGS = -Wall -pedantic
+WCFLAGS = -Wall -Wextra -pedantic
UCFLAGS = $(CPPFLAGS) $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS $(UTF8PROC_DEFINES)
LDFLAG_SHARED = -shared
SOFLAG = -Wl,-soname
int main(int argc, char **argv)
{
- char buf[8192];
+ unsigned char buf[8192];
FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL;
utf8proc_uint8_t src[1024];
while (buf[bi]) {
bi = skipspaces(buf, bi);
- if ((uint8_t)buf[bi] == 0xc3 && (uint8_t)buf[bi+1] == 0xb7) { /* U+00f7 = grapheme break */
+ if (buf[bi] == 0xc3 && buf[bi+1] == 0xb7) { /* U+00f7 = grapheme break */
src[si++] = '/';
bi += 2;
}
- else if ((uint8_t)buf[bi] == 0xc3 && (uint8_t)buf[bi+1] == 0x97) { /* U+00d7 = no break */
+ else if (buf[bi] == 0xc3 && buf[bi+1] == 0x97) { /* U+00d7 = no break */
bi += 2;
}
else if (buf[bi] == '#') { /* start of comments */
break;
}
else { /* hex-encoded codepoint */
- size_t len = encode((char*) (src + si), buf + bi) - 1;
+ size_t len = encode((unsigned char*) (src + si), buf + bi) - 1;
while (src[si]) ++si; /* advance to NUL termination */
bi += len;
}
uint32_t byt;
unsigned char buf[16];
+ (void) argc; (void) argv; /* unused */
+
tests = error = 0;
// Check valid sequences that were considered valid erroneously before
CHECKVALID(3, 0xbe, 4);
CHECKVALID(3, 0xbf, 4);
}
-
+
// Continuation byte not after lead
for (byt = 0x80; byt < 0xc0; byt++) {
CHECKINVALID(0, byt, 1);
#include "tests.h"
#define CHECK_NORM(NRM, norm, src) { \
- char *src_norm = (char*) utf8proc_ ## NRM((utf8proc_uint8_t*) src); \
- check(!strcmp(norm, src_norm), \
+ unsigned char *src_norm = (unsigned char*) utf8proc_ ## NRM((utf8proc_uint8_t*) src); \
+ check(!strcmp((char *) norm, (char *) src_norm), \
"normalization failed for %s -> %s", src, norm); \
free(src_norm); \
}
int main(int argc, char **argv)
{
- char buf[8192];
+ unsigned char buf[8192];
FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL;
- char source[1024], NFC[1024], NFD[1024], NFKC[1024], NFKD[1024];
+ unsigned char source[1024], NFC[1024], NFD[1024], NFKC[1024], NFKD[1024];
check(f != NULL, "error opening NormalizationTest.txt");
while (simple_getline(buf, f) > 0) {
}
}
-size_t skipspaces(const char *buf, size_t i)
+size_t skipspaces(const unsigned char *buf, size_t i)
{
while (isspace(buf[i])) ++i;
return i;
separated by whitespace, and terminated by any character not in
[0-9a-fA-F] or whitespace, then stores the corresponding utf8 string
in dest, returning the number of bytes read from buf */
-size_t encode(char *dest, const char *buf)
+size_t encode(unsigned char *dest, const unsigned char *buf)
{
size_t i = 0, j, d = 0;
for (;;) {
dest[d] = 0; /* NUL-terminate destination string */
return i + 1;
}
- check(sscanf(buf + i, "%x", (unsigned int *)&c) == 1, "invalid hex input %s", buf+i);
+ check(sscanf((char *) (buf + i), "%x", (unsigned int *)&c) == 1, "invalid hex input %s", buf+i);
i = j; /* skip to char after hex input */
d += utf8proc_encode_char(c, (utf8proc_uint8_t *) (dest + d));
}
}
/* simplistic, portable replacement for getline, sufficient for our tests */
-size_t simple_getline(char buf[8192], FILE *f) {
+size_t simple_getline(unsigned char buf[8192], FILE *f) {
size_t i = 0;
while (i < 8191) {
int c = getc(f);
if (c == EOF || c == '\n') break;
- buf[i++] = (char) ((uint8_t) c);
+ buf[i++] = (unsigned char) c;
}
buf[i] = 0;
return i;
extern size_t lineno;
void check(int cond, const char *format, ...);
-size_t skipspaces(const char *buf, size_t i);
-size_t encode(char *dest, const char *buf);
-size_t simple_getline(char buf[8192], FILE *f);
+size_t skipspaces(const unsigned char *buf, size_t i);
+size_t encode(unsigned char *dest, const unsigned char *buf);
+size_t simple_getline(unsigned char buf[8192], FILE *f);